//
//  XXSPFenLeiTableView.m
//  ShangChengMoBan
//
//  Created by 张铁军 on 16/8/30.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "XXSPFenLeiTableView.h"


@implementation XXSPFenLeiTableView
{
    NSArray * _arr;
}
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self request];
    }
    return self;
}

-(void)initView{
    
    self.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    
    _myTableView = [[RWScrollView alloc]initWithFrame:CGRectMake(self.width/3*2, 0, self.width/3, self.height)];
    _myTableView.backgroundColor = [UIColor whiteColor];
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    [self addSubview:_myTableView];
 }
-(void)request{
[NetWorking NEWjieKouQingQiu:XXSC_FenLei ANDIP:IP And:nil anBlock:^(NSDictionary *dic, NSError *error) {
    if (!error) {
        if ([dic[Code] intValue] == 200) {
            _arr = dic[Response];
            
        }
       [_myTableView reloadData];
    }
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tableCell"];
    }
    cell.imageView.image = [UIImage imageNamed:@""];
    cell.textLabel.text = _arr[indexPath.row][@"name"];
    cell.textLabel.textColor = MaintextColor;
    cell.textLabel.font = [UIFont systemFontOfSize:PuTongFont];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView cellForRowAtIndexPath:indexPath].selected = NO;
    [self.delegate fenLeiTapClicked:_arr[indexPath.row]];
    
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
